import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
import 'package:search_people/page/home/main/views/dynamic_cell.dart';
import 'package:search_people/utils/util.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class SubscribePage extends StatelessWidget {
  SubscribePage({Key? key}) : super(key: key);
  final controller = Get.put(SubscribeController());
  final state = Get.find<SubscribeController>().state;
  // 主视图
  Widget _buildView() {
    return isZeroList(state.list)
        ? HelloWidget()
        : ListView.builder(
            itemBuilder: (ctx, idx) {
              var md = state.list![idx];
              return DynamicCell(md: md);
            },
            itemCount: state.list?.length ?? 0,
          );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SubscribeController>(
      builder: (_) {
        return Scaffold(
          body: SafeArea(
            child: SmartRefresher(
              onRefresh: controller.onRefresh,
              onLoading: controller.onLoading,
              enablePullDown: true,
              enablePullUp: true,
              controller: state.rc,
              child: _buildView(),
            ),
          ),
        );
      },
    );
  }
}
